{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_input = 784\n",
    "n_output = 10\n",
    "weights = {\n",
    "    'wc1' : tf.Variable(tf.random_normal([3,3,1,64],stddev=0.1)),  #(H,W,in_channel,out_channel) D:deepth N:输出的label数，这一个卷积层输出为为64  3，3对应filter\n",
    "    'wc2' : tf.Variable(tf.random_normal([3,3,64,128],stddev=0.1)), # 上一层的输出为64层\n",
    "    'wd1' : tf.Variable(tf.random_normal([7*7*128,1024],stddev=0.1)), # 28->卷积1->->pooling1->j卷积2->->pooling2  H变成7\n",
    "    'wd2' : tf.Variable(tf.random_normal([1024,n_output],stddev=0.1))\n",
    " }\n",
    "\n",
    "biases = {\n",
    "    \n",
    "    'bc1' : tf.Variable(tf.random_normal([64],stddev=0.1)),\n",
    "    'bc2' : tf.Variable(tf.random_normal([128],stddev=0.1)),\n",
    "    'bd1' : tf.Variable(tf.random_normal([1024],stddev=0.1)),\n",
    "    'bd2' : tf.Variable(tf.random_normal([n_output],stddev=0.1))\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (<ipython-input-10-c99b536a42cb>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-10-c99b536a42cb>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    def conv_basic(input, _w, _b, _keepratio):\u001b[0m\n\u001b[1;37m                                              ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "def conv_basic(input, _w, _b, _keepratio):\n",
    "    # input reshape 为tf能接受的维度\n",
    "    _input_r = tf.reshape(_inpiut,shape=[-1,28,28,1])  #(N,H,W,C)  N=-1定为动态，其他定好，第一维是可以算出来  C:channel  灰度图，只有1\n",
    "    \n",
    "    _conv1 = tf.nn.conv2d(_inpuit_r,_w['wc1'],strides=[1,1,1,1],padding='SAME')\n",
    "    _conv1 = tf.nn.relu(tf.nn.bias_add(_conv1,_b['bc1']))\n",
    "    _pool1 = tf.nn.max_pool(_conv1,_b['bc1'],ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')\n",
    "    _pool_dr1 = tf.nn.dropout(_pool1,_keepratio)\n",
    "    \n",
    "    _conv2 = tf.nn.conv2d(_inpuit_r,_w['wc2'],strides=[1,1,1,1],padding='SAME)\n",
    "    _conv2 = tf.nn.relu(tf.nn.bias_add(_conv2,_b['bc2']))\n",
    "    _pool2 = tf.nn.max_pool(_conv2,_b['bc2'],ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')\n",
    "    _pool_dr2 = tf.nn.dropout(_pool2,_keepratio)\n",
    "                          \n",
    "                          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function conv2d in module tensorflow.python.ops.gen_nn_ops:\n",
      "\n",
      "conv2d(input, filter, strides, padding, use_cudnn_on_gpu=True, data_format='NHWC', dilations=[1, 1, 1, 1], name=None)\n",
      "    Computes a 2-D convolution given 4-D `input` and `filter` tensors.\n",
      "    \n",
      "    Given an input tensor of shape `[batch, in_height, in_width, in_channels]`\n",
      "    and a filter / kernel tensor of shape\n",
      "    `[filter_height, filter_width, in_channels, out_channels]`, this op\n",
      "    performs the following:\n",
      "    \n",
      "    1. Flattens the filter to a 2-D matrix with shape\n",
      "       `[filter_height * filter_width * in_channels, output_channels]`.\n",
      "    2. Extracts image patches from the input tensor to form a *virtual*\n",
      "       tensor of shape `[batch, out_height, out_width,\n",
      "       filter_height * filter_width * in_channels]`.\n",
      "    3. For each patch, right-multiplies the filter matrix and the image patch\n",
      "       vector.\n",
      "    \n",
      "    In detail, with the default NHWC format,\n",
      "    \n",
      "        output[b, i, j, k] =\n",
      "            sum_{di, dj, q} input[b, strides[1] * i + di, strides[2] * j + dj, q] *\n",
      "                            filter[di, dj, q, k]\n",
      "    \n",
      "    Must have `strides[0] = strides[3] = 1`.  For the most common case of the same\n",
      "    horizontal and vertices strides, `strides = [1, stride, stride, 1]`.\n",
      "    \n",
      "    Args:\n",
      "      input: A `Tensor`. Must be one of the following types: `half`, `bfloat16`, `float32`, `float64`.\n",
      "        A 4-D tensor. The dimension order is interpreted according to the value\n",
      "        of `data_format`, see below for details.\n",
      "      filter: A `Tensor`. Must have the same type as `input`.\n",
      "        A 4-D tensor of shape\n",
      "        `[filter_height, filter_width, in_channels, out_channels]`\n",
      "      strides: A list of `ints`.\n",
      "        1-D tensor of length 4.  The stride of the sliding window for each\n",
      "        dimension of `input`. The dimension order is determined by the value of\n",
      "        `data_format`, see below for details.\n",
      "      padding: A `string` from: `\"SAME\", \"VALID\"`.\n",
      "        The type of padding algorithm to use.\n",
      "      use_cudnn_on_gpu: An optional `bool`. Defaults to `True`.\n",
      "      data_format: An optional `string` from: `\"NHWC\", \"NCHW\"`. Defaults to `\"NHWC\"`.\n",
      "        Specify the data format of the input and output data. With the\n",
      "        default format \"NHWC\", the data is stored in the order of:\n",
      "            [batch, height, width, channels].\n",
      "        Alternatively, the format could be \"NCHW\", the data storage order of:\n",
      "            [batch, channels, height, width].\n",
      "      dilations: An optional list of `ints`. Defaults to `[1, 1, 1, 1]`.\n",
      "        1-D tensor of length 4.  The dilation factor for each dimension of\n",
      "        `input`. If set to k > 1, there will be k-1 skipped cells between each\n",
      "        filter element on that dimension. The dimension order is determined by the\n",
      "        value of `data_format`, see above for details. Dilations in the batch and\n",
      "        depth dimensions must be 1.\n",
      "      name: A name for the operation (optional).\n",
      "    \n",
      "    Returns:\n",
      "      A `Tensor`. Has the same type as `input`.\n",
      "\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "print(help(tf.nn.conv2d))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
